# -*- coding:utf-8 -*-
import os


def merge_video_audio_ffmpeg(video_url, audio_url):
    source_url = video_url[:video_url.rfind('/')]
    new_video_name = video_url[video_url.rfind('/'): video_url.rfind('.')]
    count = 0
    listdir = os.listdir(source_url)
    for file_name in listdir:
        find = file_name.find(new_video_name[1:])
        if find >= 0:
            count = count + 1

    shell = 'ffmpeg -i ' + video_url + ' -i ' + audio_url + ' ' + source_url + new_video_name + '(' + str(
        count) + ').mp4'
    print(shell)
    getcwdu = os.getcwd()
    print(getcwdu)
    popen = os.popen(shell)
    read = popen.read()
    for i in read:
        print(i)
    input("请输入：")


if __name__ == '__main__':
    merge_video_audio_ffmpeg("./source/videoplayback.mp4", "./source/videoplayback.weba")
